#ifndef MOSES_PATTERN_H
#define MOSES_PATTERN_H

#include "Item.h"
#include "Literal.h"
#include "Expr.h"
#include "Value.h"
#include "Runtime.h"

namespace moses
{
	
	class Pattern : public Item
	{
	public:
		MOSES_ITEM_VISITABLE()
		
		virtual ~Pattern() {}
		
		virtual bool Match(Runtime *pEnv, Expr *pExpr) = 0;
		virtual Type GetType() = 0;
	};
	
	class LiteralPattern : public Pattern
	{
	public:
		LiteralPattern(Literal *pLiteral)
		: m_pLiteral(pLiteral)
		{
		}
		
		virtual bool Match(Runtime *pEnv, Expr *pExpr)
		{
			return m_pLiteral->Evaluate(pEnv) == pExpr->Evaluate(pEnv);
		}
		
		virtual Type GetType()
		{
			return m_pLiteral->GetValue().GetType();
		}
		
	private:
		Literal *m_pLiteral;
	};
	
	class ConstPattern : public Pattern
	{
	public:
		ConstPattern(bool match)
		: m_match(match)
		{
		}
		
		virtual bool Match(Runtime *pEnv, Expr *pExpr)
		{
			return m_match;
		}
		
		virtual Type GetType()
		{
			return Type(Type::ANY);
		}
		
	private:
		bool m_match;
	};
}

#endif